package com.jsle.financial.service;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.jsle.financial.dao.WorkflowDao;
import com.jsle.financial.domain.Node;
import com.jsle.financial.domain.User;
import com.jsle.financial.domain.Workflow;
import com.jsle.financial.manager.WorkflowManager;
import com.jsle.financial.util.Constants;
import com.jsle.financial.vo.Result;

public class WorkflowServiceImpl implements WorkflowService{
	private Log log = LogFactory.getLog(WorkflowServiceImpl.class);
	@Resource
	private WorkflowManager workflowManager;
	@Resource
	private WorkflowDao workflowDao;
	public Result saveAmountWorkflow(Workflow workflow) {
		Result result = new Result();
		try {
			result = workflowManager.saveAmountWorkflow(workflow);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("WorkflowServiceImpl error## "+ e.getMessage());
		}
		return result;
	}

	public Result saveAmountNode(Node node){
		Result result = new Result();
		try {
			result = workflowManager.saveAmountNode(node);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("saveAmountNode error## "+ e.getMessage());
		}
		return result;
	}
	
	public Result queryWorkflowByCode(String workflowCode){
		Result result = new Result();
		try {
			result = workflowDao.queryWorkflowByCode(workflowCode);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("queryWorkflowByCode Manager error## "+ e.getMessage());
		}
		return result;
	}
	
	public Result updateWorkflow(Workflow workflow){
		Result result = new Result();
		try {
			result = workflowDao.updateWorkflow(workflow);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("updateWorkflow Manager error## "+ e.getMessage());
		}
		return result;
	}
	
	public Result queryWorkflowByUser(User user){
		Result result = new Result();
		try {
			result = workflowDao.queryWorkflowByUser(user);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("queryWorkflowByUser Manager error## "+ e.getMessage());
		}
		return result;
	}
	public Result queryWorkflowBySelf(Workflow workflow){
		Result result = new Result();
		try {
			result = workflowDao.queryWorkflowBySelf(workflow);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("queryWorkflowByUser Manager error## "+ e.getMessage());
		}
		return result;
	}
	public Result queryWorkflowAndNodes(Workflow workflow){
		Result result = new Result();
		try {
			result = workflowDao.queryWorkflowAndNodes(workflow);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("queryWorkflowAndNodes Manager error## "+ e.getMessage());
		}
		return result;
	}
	public Result queryNodes(Workflow workflow){
		Result result = new Result();
		try {
			result = workflowDao.queryNodes(workflow);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("queryNodes Manager error## "+ e.getMessage());
		}
		return result;
	}
	

	public Result updateNode(Node node){
		Result result = new Result();
		try {
			result = workflowManager.updateNode(node);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("updateNode Manager error## "+ e.getMessage());
		}
		return result;
	}

	public Result queryWorkflowByWorkflow(Workflow workflow) {
		Result result = new Result();
		try {
			result = workflowDao.queryWorkflowByWorkflow(workflow);
		} catch (Exception e) {
			result.setResultCode(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_CODE);
			result.setResultMessage(String.format(Constants.Service.FC_RESULT_INSERT_SERVICE_ERROR_MESSAGE, "User"));
			log.error("queryWorkflowByWorkflow Manager error## "+ e.getMessage());
		}
		return result;
	}
}
